package com.example.rabbitmq.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

public class RabbitMQUtil {

    public static Channel createChannel(int channelNum) throws Exception {
        //创建rabbitmq的连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        //factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        String connectionName="quickStartConnection";
        //获取连接。连接不同，则相互独立
        Connection connection = factory.newConnection(connectionName);
        //获取连接的信道channel
        Channel channel = connection.createChannel(channelNum);
        return channel;
    }
}
